/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.skali.cabdirectories.service.persistence;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import com.skali.cabdirectories.NoSuchCABDirectory_DLFileEntryMappingException;
import com.skali.cabdirectories.model.CABDirectory_DLFileEntryMapping;
import com.skali.cabdirectories.model.impl.CABDirectory_DLFileEntryMappingImpl;
import com.skali.cabdirectories.model.impl.CABDirectory_DLFileEntryMappingModelImpl;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the c a b directory_ d l file entry mapping service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author Prabhakar
 * @see CABDirectory_DLFileEntryMappingPersistence
 * @see CABDirectory_DLFileEntryMappingUtil
 * @generated
 */
public class CABDirectory_DLFileEntryMappingPersistenceImpl
	extends BasePersistenceImpl<CABDirectory_DLFileEntryMapping>
	implements CABDirectory_DLFileEntryMappingPersistence {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. Always use {@link CABDirectory_DLFileEntryMappingUtil} to access the c a b directory_ d l file entry mapping persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
	 */
	public static final String FINDER_CLASS_NAME_ENTITY = CABDirectory_DLFileEntryMappingImpl.class.getName();
	public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List1";
	public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List2";
	public static final FinderPath FINDER_PATH_FETCH_BY_DLFILEENTRYID = new FinderPath(CABDirectory_DLFileEntryMappingModelImpl.ENTITY_CACHE_ENABLED,
			CABDirectory_DLFileEntryMappingModelImpl.FINDER_CACHE_ENABLED,
			CABDirectory_DLFileEntryMappingImpl.class,
			FINDER_CLASS_NAME_ENTITY, "fetchBydlFileEntryId",
			new String[] { Long.class.getName() },
			CABDirectory_DLFileEntryMappingModelImpl.DLFILEENTRYID_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_DLFILEENTRYID = new FinderPath(CABDirectory_DLFileEntryMappingModelImpl.ENTITY_CACHE_ENABLED,
			CABDirectory_DLFileEntryMappingModelImpl.FINDER_CACHE_ENABLED,
			Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"countBydlFileEntryId", new String[] { Long.class.getName() });
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CABDirectory_DLFileEntryMappingModelImpl.ENTITY_CACHE_ENABLED,
			CABDirectory_DLFileEntryMappingModelImpl.FINDER_CACHE_ENABLED,
			CABDirectory_DLFileEntryMappingImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CABDirectory_DLFileEntryMappingModelImpl.ENTITY_CACHE_ENABLED,
			CABDirectory_DLFileEntryMappingModelImpl.FINDER_CACHE_ENABLED,
			CABDirectory_DLFileEntryMappingImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CABDirectory_DLFileEntryMappingModelImpl.ENTITY_CACHE_ENABLED,
			CABDirectory_DLFileEntryMappingModelImpl.FINDER_CACHE_ENABLED,
			Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll",
			new String[0]);

	/**
	 * Caches the c a b directory_ d l file entry mapping in the entity cache if it is enabled.
	 *
	 * @param cabDirectory_DLFileEntryMapping the c a b directory_ d l file entry mapping
	 */
	public void cacheResult(
		CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping) {
		EntityCacheUtil.putResult(CABDirectory_DLFileEntryMappingModelImpl.ENTITY_CACHE_ENABLED,
			CABDirectory_DLFileEntryMappingImpl.class,
			cabDirectory_DLFileEntryMapping.getPrimaryKey(),
			cabDirectory_DLFileEntryMapping);

		FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFILEENTRYID,
			new Object[] {
				Long.valueOf(cabDirectory_DLFileEntryMapping.getDlFileEntryId())
			}, cabDirectory_DLFileEntryMapping);

		cabDirectory_DLFileEntryMapping.resetOriginalValues();
	}

	/**
	 * Caches the c a b directory_ d l file entry mappings in the entity cache if it is enabled.
	 *
	 * @param cabDirectory_DLFileEntryMappings the c a b directory_ d l file entry mappings
	 */
	public void cacheResult(
		List<CABDirectory_DLFileEntryMapping> cabDirectory_DLFileEntryMappings) {
		for (CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping : cabDirectory_DLFileEntryMappings) {
			if (EntityCacheUtil.getResult(
						CABDirectory_DLFileEntryMappingModelImpl.ENTITY_CACHE_ENABLED,
						CABDirectory_DLFileEntryMappingImpl.class,
						cabDirectory_DLFileEntryMapping.getPrimaryKey()) == null) {
				cacheResult(cabDirectory_DLFileEntryMapping);
			}
			else {
				cabDirectory_DLFileEntryMapping.resetOriginalValues();
			}
		}
	}

	/**
	 * Clears the cache for all c a b directory_ d l file entry mappings.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache() {
		if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
			CacheRegistryUtil.clear(CABDirectory_DLFileEntryMappingImpl.class.getName());
		}

		EntityCacheUtil.clearCache(CABDirectory_DLFileEntryMappingImpl.class.getName());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	/**
	 * Clears the cache for the c a b directory_ d l file entry mapping.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache(
		CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping) {
		EntityCacheUtil.removeResult(CABDirectory_DLFileEntryMappingModelImpl.ENTITY_CACHE_ENABLED,
			CABDirectory_DLFileEntryMappingImpl.class,
			cabDirectory_DLFileEntryMapping.getPrimaryKey());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		clearUniqueFindersCache(cabDirectory_DLFileEntryMapping);
	}

	@Override
	public void clearCache(
		List<CABDirectory_DLFileEntryMapping> cabDirectory_DLFileEntryMappings) {
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		for (CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping : cabDirectory_DLFileEntryMappings) {
			EntityCacheUtil.removeResult(CABDirectory_DLFileEntryMappingModelImpl.ENTITY_CACHE_ENABLED,
				CABDirectory_DLFileEntryMappingImpl.class,
				cabDirectory_DLFileEntryMapping.getPrimaryKey());

			clearUniqueFindersCache(cabDirectory_DLFileEntryMapping);
		}
	}

	protected void cacheUniqueFindersCache(
		CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping) {
		if (cabDirectory_DLFileEntryMapping.isNew()) {
			Object[] args = new Object[] {
					Long.valueOf(cabDirectory_DLFileEntryMapping.getDlFileEntryId())
				};

			FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_DLFILEENTRYID, args,
				Long.valueOf(1));
			FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFILEENTRYID, args,
				cabDirectory_DLFileEntryMapping);
		}
		else {
			CABDirectory_DLFileEntryMappingModelImpl cabDirectory_DLFileEntryMappingModelImpl =
				(CABDirectory_DLFileEntryMappingModelImpl)cabDirectory_DLFileEntryMapping;

			if ((cabDirectory_DLFileEntryMappingModelImpl.getColumnBitmask() &
					FINDER_PATH_FETCH_BY_DLFILEENTRYID.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						Long.valueOf(cabDirectory_DLFileEntryMapping.getDlFileEntryId())
					};

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_DLFILEENTRYID,
					args, Long.valueOf(1));
				FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFILEENTRYID,
					args, cabDirectory_DLFileEntryMapping);
			}
		}
	}

	protected void clearUniqueFindersCache(
		CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping) {
		CABDirectory_DLFileEntryMappingModelImpl cabDirectory_DLFileEntryMappingModelImpl =
			(CABDirectory_DLFileEntryMappingModelImpl)cabDirectory_DLFileEntryMapping;

		Object[] args = new Object[] {
				Long.valueOf(cabDirectory_DLFileEntryMapping.getDlFileEntryId())
			};

		FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_DLFILEENTRYID, args);
		FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DLFILEENTRYID, args);

		if ((cabDirectory_DLFileEntryMappingModelImpl.getColumnBitmask() &
				FINDER_PATH_FETCH_BY_DLFILEENTRYID.getColumnBitmask()) != 0) {
			args = new Object[] {
					Long.valueOf(cabDirectory_DLFileEntryMappingModelImpl.getOriginalDlFileEntryId())
				};

			FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_DLFILEENTRYID,
				args);
			FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DLFILEENTRYID,
				args);
		}
	}

	/**
	 * Creates a new c a b directory_ d l file entry mapping with the primary key. Does not add the c a b directory_ d l file entry mapping to the database.
	 *
	 * @param mappingId the primary key for the new c a b directory_ d l file entry mapping
	 * @return the new c a b directory_ d l file entry mapping
	 */
	public CABDirectory_DLFileEntryMapping create(long mappingId) {
		CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping = new CABDirectory_DLFileEntryMappingImpl();

		cabDirectory_DLFileEntryMapping.setNew(true);
		cabDirectory_DLFileEntryMapping.setPrimaryKey(mappingId);

		return cabDirectory_DLFileEntryMapping;
	}

	/**
	 * Removes the c a b directory_ d l file entry mapping with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param mappingId the primary key of the c a b directory_ d l file entry mapping
	 * @return the c a b directory_ d l file entry mapping that was removed
	 * @throws com.skali.cabdirectories.NoSuchCABDirectory_DLFileEntryMappingException if a c a b directory_ d l file entry mapping with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public CABDirectory_DLFileEntryMapping remove(long mappingId)
		throws NoSuchCABDirectory_DLFileEntryMappingException, SystemException {
		return remove(Long.valueOf(mappingId));
	}

	/**
	 * Removes the c a b directory_ d l file entry mapping with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param primaryKey the primary key of the c a b directory_ d l file entry mapping
	 * @return the c a b directory_ d l file entry mapping that was removed
	 * @throws com.skali.cabdirectories.NoSuchCABDirectory_DLFileEntryMappingException if a c a b directory_ d l file entry mapping with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public CABDirectory_DLFileEntryMapping remove(Serializable primaryKey)
		throws NoSuchCABDirectory_DLFileEntryMappingException, SystemException {
		Session session = null;

		try {
			session = openSession();

			CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping = (CABDirectory_DLFileEntryMapping)session.get(CABDirectory_DLFileEntryMappingImpl.class,
					primaryKey);

			if (cabDirectory_DLFileEntryMapping == null) {
				if (_log.isWarnEnabled()) {
					_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
				}

				throw new NoSuchCABDirectory_DLFileEntryMappingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
					primaryKey);
			}

			return remove(cabDirectory_DLFileEntryMapping);
		}
		catch (NoSuchCABDirectory_DLFileEntryMappingException nsee) {
			throw nsee;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	@Override
	protected CABDirectory_DLFileEntryMapping removeImpl(
		CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping)
		throws SystemException {
		cabDirectory_DLFileEntryMapping = toUnwrappedModel(cabDirectory_DLFileEntryMapping);

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.delete(session, cabDirectory_DLFileEntryMapping);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		clearCache(cabDirectory_DLFileEntryMapping);

		return cabDirectory_DLFileEntryMapping;
	}

	@Override
	public CABDirectory_DLFileEntryMapping updateImpl(
		com.skali.cabdirectories.model.CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping,
		boolean merge) throws SystemException {
		cabDirectory_DLFileEntryMapping = toUnwrappedModel(cabDirectory_DLFileEntryMapping);

		boolean isNew = cabDirectory_DLFileEntryMapping.isNew();

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.update(session, cabDirectory_DLFileEntryMapping,
				merge);

			cabDirectory_DLFileEntryMapping.setNew(false);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

		if (isNew ||
				!CABDirectory_DLFileEntryMappingModelImpl.COLUMN_BITMASK_ENABLED) {
			FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
		}

		EntityCacheUtil.putResult(CABDirectory_DLFileEntryMappingModelImpl.ENTITY_CACHE_ENABLED,
			CABDirectory_DLFileEntryMappingImpl.class,
			cabDirectory_DLFileEntryMapping.getPrimaryKey(),
			cabDirectory_DLFileEntryMapping);

		clearUniqueFindersCache(cabDirectory_DLFileEntryMapping);
		cacheUniqueFindersCache(cabDirectory_DLFileEntryMapping);

		return cabDirectory_DLFileEntryMapping;
	}

	protected CABDirectory_DLFileEntryMapping toUnwrappedModel(
		CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping) {
		if (cabDirectory_DLFileEntryMapping instanceof CABDirectory_DLFileEntryMappingImpl) {
			return cabDirectory_DLFileEntryMapping;
		}

		CABDirectory_DLFileEntryMappingImpl cabDirectory_DLFileEntryMappingImpl = new CABDirectory_DLFileEntryMappingImpl();

		cabDirectory_DLFileEntryMappingImpl.setNew(cabDirectory_DLFileEntryMapping.isNew());
		cabDirectory_DLFileEntryMappingImpl.setPrimaryKey(cabDirectory_DLFileEntryMapping.getPrimaryKey());

		cabDirectory_DLFileEntryMappingImpl.setMappingId(cabDirectory_DLFileEntryMapping.getMappingId());
		cabDirectory_DLFileEntryMappingImpl.setSammId(cabDirectory_DLFileEntryMapping.getSammId());
		cabDirectory_DLFileEntryMappingImpl.setDlFileEntryId(cabDirectory_DLFileEntryMapping.getDlFileEntryId());

		return cabDirectory_DLFileEntryMappingImpl;
	}

	/**
	 * Returns the c a b directory_ d l file entry mapping with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
	 *
	 * @param primaryKey the primary key of the c a b directory_ d l file entry mapping
	 * @return the c a b directory_ d l file entry mapping
	 * @throws com.liferay.portal.NoSuchModelException if a c a b directory_ d l file entry mapping with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public CABDirectory_DLFileEntryMapping findByPrimaryKey(
		Serializable primaryKey) throws NoSuchModelException, SystemException {
		return findByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the c a b directory_ d l file entry mapping with the primary key or throws a {@link com.skali.cabdirectories.NoSuchCABDirectory_DLFileEntryMappingException} if it could not be found.
	 *
	 * @param mappingId the primary key of the c a b directory_ d l file entry mapping
	 * @return the c a b directory_ d l file entry mapping
	 * @throws com.skali.cabdirectories.NoSuchCABDirectory_DLFileEntryMappingException if a c a b directory_ d l file entry mapping with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public CABDirectory_DLFileEntryMapping findByPrimaryKey(long mappingId)
		throws NoSuchCABDirectory_DLFileEntryMappingException, SystemException {
		CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping = fetchByPrimaryKey(mappingId);

		if (cabDirectory_DLFileEntryMapping == null) {
			if (_log.isWarnEnabled()) {
				_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + mappingId);
			}

			throw new NoSuchCABDirectory_DLFileEntryMappingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
				mappingId);
		}

		return cabDirectory_DLFileEntryMapping;
	}

	/**
	 * Returns the c a b directory_ d l file entry mapping with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param primaryKey the primary key of the c a b directory_ d l file entry mapping
	 * @return the c a b directory_ d l file entry mapping, or <code>null</code> if a c a b directory_ d l file entry mapping with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public CABDirectory_DLFileEntryMapping fetchByPrimaryKey(
		Serializable primaryKey) throws SystemException {
		return fetchByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the c a b directory_ d l file entry mapping with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param mappingId the primary key of the c a b directory_ d l file entry mapping
	 * @return the c a b directory_ d l file entry mapping, or <code>null</code> if a c a b directory_ d l file entry mapping with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public CABDirectory_DLFileEntryMapping fetchByPrimaryKey(long mappingId)
		throws SystemException {
		CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping = (CABDirectory_DLFileEntryMapping)EntityCacheUtil.getResult(CABDirectory_DLFileEntryMappingModelImpl.ENTITY_CACHE_ENABLED,
				CABDirectory_DLFileEntryMappingImpl.class, mappingId);

		if (cabDirectory_DLFileEntryMapping == _nullCABDirectory_DLFileEntryMapping) {
			return null;
		}

		if (cabDirectory_DLFileEntryMapping == null) {
			Session session = null;

			boolean hasException = false;

			try {
				session = openSession();

				cabDirectory_DLFileEntryMapping = (CABDirectory_DLFileEntryMapping)session.get(CABDirectory_DLFileEntryMappingImpl.class,
						Long.valueOf(mappingId));
			}
			catch (Exception e) {
				hasException = true;

				throw processException(e);
			}
			finally {
				if (cabDirectory_DLFileEntryMapping != null) {
					cacheResult(cabDirectory_DLFileEntryMapping);
				}
				else if (!hasException) {
					EntityCacheUtil.putResult(CABDirectory_DLFileEntryMappingModelImpl.ENTITY_CACHE_ENABLED,
						CABDirectory_DLFileEntryMappingImpl.class, mappingId,
						_nullCABDirectory_DLFileEntryMapping);
				}

				closeSession(session);
			}
		}

		return cabDirectory_DLFileEntryMapping;
	}

	/**
	 * Returns the c a b directory_ d l file entry mapping where dlFileEntryId = &#63; or throws a {@link com.skali.cabdirectories.NoSuchCABDirectory_DLFileEntryMappingException} if it could not be found.
	 *
	 * @param dlFileEntryId the dl file entry ID
	 * @return the matching c a b directory_ d l file entry mapping
	 * @throws com.skali.cabdirectories.NoSuchCABDirectory_DLFileEntryMappingException if a matching c a b directory_ d l file entry mapping could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public CABDirectory_DLFileEntryMapping findBydlFileEntryId(
		long dlFileEntryId)
		throws NoSuchCABDirectory_DLFileEntryMappingException, SystemException {
		CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping = fetchBydlFileEntryId(dlFileEntryId);

		if (cabDirectory_DLFileEntryMapping == null) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("dlFileEntryId=");
			msg.append(dlFileEntryId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			if (_log.isWarnEnabled()) {
				_log.warn(msg.toString());
			}

			throw new NoSuchCABDirectory_DLFileEntryMappingException(msg.toString());
		}

		return cabDirectory_DLFileEntryMapping;
	}

	/**
	 * Returns the c a b directory_ d l file entry mapping where dlFileEntryId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
	 *
	 * @param dlFileEntryId the dl file entry ID
	 * @return the matching c a b directory_ d l file entry mapping, or <code>null</code> if a matching c a b directory_ d l file entry mapping could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public CABDirectory_DLFileEntryMapping fetchBydlFileEntryId(
		long dlFileEntryId) throws SystemException {
		return fetchBydlFileEntryId(dlFileEntryId, true);
	}

	/**
	 * Returns the c a b directory_ d l file entry mapping where dlFileEntryId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
	 *
	 * @param dlFileEntryId the dl file entry ID
	 * @param retrieveFromCache whether to use the finder cache
	 * @return the matching c a b directory_ d l file entry mapping, or <code>null</code> if a matching c a b directory_ d l file entry mapping could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public CABDirectory_DLFileEntryMapping fetchBydlFileEntryId(
		long dlFileEntryId, boolean retrieveFromCache)
		throws SystemException {
		Object[] finderArgs = new Object[] { dlFileEntryId };

		Object result = null;

		if (retrieveFromCache) {
			result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_DLFILEENTRYID,
					finderArgs, this);
		}

		if (result instanceof CABDirectory_DLFileEntryMapping) {
			CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping = (CABDirectory_DLFileEntryMapping)result;

			if ((dlFileEntryId != cabDirectory_DLFileEntryMapping.getDlFileEntryId())) {
				result = null;
			}
		}

		if (result == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_SELECT_CABDIRECTORY_DLFILEENTRYMAPPING_WHERE);

			query.append(_FINDER_COLUMN_DLFILEENTRYID_DLFILEENTRYID_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(dlFileEntryId);

				List<CABDirectory_DLFileEntryMapping> list = q.list();

				result = list;

				CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping = null;

				if (list.isEmpty()) {
					FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFILEENTRYID,
						finderArgs, list);
				}
				else {
					cabDirectory_DLFileEntryMapping = list.get(0);

					cacheResult(cabDirectory_DLFileEntryMapping);

					if ((cabDirectory_DLFileEntryMapping.getDlFileEntryId() != dlFileEntryId)) {
						FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFILEENTRYID,
							finderArgs, cabDirectory_DLFileEntryMapping);
					}
				}

				return cabDirectory_DLFileEntryMapping;
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (result == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DLFILEENTRYID,
						finderArgs);
				}

				closeSession(session);
			}
		}
		else {
			if (result instanceof List<?>) {
				return null;
			}
			else {
				return (CABDirectory_DLFileEntryMapping)result;
			}
		}
	}

	/**
	 * Returns all the c a b directory_ d l file entry mappings.
	 *
	 * @return the c a b directory_ d l file entry mappings
	 * @throws SystemException if a system exception occurred
	 */
	public List<CABDirectory_DLFileEntryMapping> findAll()
		throws SystemException {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the c a b directory_ d l file entry mappings.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of c a b directory_ d l file entry mappings
	 * @param end the upper bound of the range of c a b directory_ d l file entry mappings (not inclusive)
	 * @return the range of c a b directory_ d l file entry mappings
	 * @throws SystemException if a system exception occurred
	 */
	public List<CABDirectory_DLFileEntryMapping> findAll(int start, int end)
		throws SystemException {
		return findAll(start, end, null);
	}

	/**
	 * Returns an ordered range of all the c a b directory_ d l file entry mappings.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of c a b directory_ d l file entry mappings
	 * @param end the upper bound of the range of c a b directory_ d l file entry mappings (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of c a b directory_ d l file entry mappings
	 * @throws SystemException if a system exception occurred
	 */
	public List<CABDirectory_DLFileEntryMapping> findAll(int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = new Object[] { start, end, orderByComparator };

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
			finderArgs = FINDER_ARGS_EMPTY;
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
			finderArgs = new Object[] { start, end, orderByComparator };
		}

		List<CABDirectory_DLFileEntryMapping> list = (List<CABDirectory_DLFileEntryMapping>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;
			String sql = null;

			if (orderByComparator != null) {
				query = new StringBundler(2 +
						(orderByComparator.getOrderByFields().length * 3));

				query.append(_SQL_SELECT_CABDIRECTORY_DLFILEENTRYMAPPING);

				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);

				sql = query.toString();
			}
			else {
				sql = _SQL_SELECT_CABDIRECTORY_DLFILEENTRYMAPPING;
			}

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				if (orderByComparator == null) {
					list = (List<CABDirectory_DLFileEntryMapping>)QueryUtil.list(q,
							getDialect(), start, end, false);

					Collections.sort(list);
				}
				else {
					list = (List<CABDirectory_DLFileEntryMapping>)QueryUtil.list(q,
							getDialect(), start, end);
				}
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Removes the c a b directory_ d l file entry mapping where dlFileEntryId = &#63; from the database.
	 *
	 * @param dlFileEntryId the dl file entry ID
	 * @return the c a b directory_ d l file entry mapping that was removed
	 * @throws SystemException if a system exception occurred
	 */
	public CABDirectory_DLFileEntryMapping removeBydlFileEntryId(
		long dlFileEntryId)
		throws NoSuchCABDirectory_DLFileEntryMappingException, SystemException {
		CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping = findBydlFileEntryId(dlFileEntryId);

		return remove(cabDirectory_DLFileEntryMapping);
	}

	/**
	 * Removes all the c a b directory_ d l file entry mappings from the database.
	 *
	 * @throws SystemException if a system exception occurred
	 */
	public void removeAll() throws SystemException {
		for (CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping : findAll()) {
			remove(cabDirectory_DLFileEntryMapping);
		}
	}

	/**
	 * Returns the number of c a b directory_ d l file entry mappings where dlFileEntryId = &#63;.
	 *
	 * @param dlFileEntryId the dl file entry ID
	 * @return the number of matching c a b directory_ d l file entry mappings
	 * @throws SystemException if a system exception occurred
	 */
	public int countBydlFileEntryId(long dlFileEntryId)
		throws SystemException {
		Object[] finderArgs = new Object[] { dlFileEntryId };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_DLFILEENTRYID,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_CABDIRECTORY_DLFILEENTRYMAPPING_WHERE);

			query.append(_FINDER_COLUMN_DLFILEENTRYID_DLFILEENTRYID_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(dlFileEntryId);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_DLFILEENTRYID,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of c a b directory_ d l file entry mappings.
	 *
	 * @return the number of c a b directory_ d l file entry mappings
	 * @throws SystemException if a system exception occurred
	 */
	public int countAll() throws SystemException {
		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
				FINDER_ARGS_EMPTY, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(_SQL_COUNT_CABDIRECTORY_DLFILEENTRYMAPPING);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
					FINDER_ARGS_EMPTY, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Initializes the c a b directory_ d l file entry mapping persistence.
	 */
	public void afterPropertiesSet() {
		String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
					com.liferay.util.service.ServiceProps.get(
						"value.object.listener.com.skali.cabdirectories.model.CABDirectory_DLFileEntryMapping")));

		if (listenerClassNames.length > 0) {
			try {
				List<ModelListener<CABDirectory_DLFileEntryMapping>> listenersList =
					new ArrayList<ModelListener<CABDirectory_DLFileEntryMapping>>();

				for (String listenerClassName : listenerClassNames) {
					Class<?> clazz = getClass();

					listenersList.add((ModelListener<CABDirectory_DLFileEntryMapping>)InstanceFactory.newInstance(
							clazz.getClassLoader(), listenerClassName));
				}

				listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
			}
			catch (Exception e) {
				_log.error(e);
			}
		}
	}

	public void destroy() {
		EntityCacheUtil.removeCache(CABDirectory_DLFileEntryMappingImpl.class.getName());
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@BeanReference(type = CABDirectories_MetadataPersistence.class)
	protected CABDirectories_MetadataPersistence cabDirectories_MetadataPersistence;
	@BeanReference(type = CABDirectory_DLFileEntryMappingPersistence.class)
	protected CABDirectory_DLFileEntryMappingPersistence cabDirectory_DLFileEntryMappingPersistence;
	@BeanReference(type = ResourcePersistence.class)
	protected ResourcePersistence resourcePersistence;
	@BeanReference(type = UserPersistence.class)
	protected UserPersistence userPersistence;
	private static final String _SQL_SELECT_CABDIRECTORY_DLFILEENTRYMAPPING = "SELECT cabDirectory_DLFileEntryMapping FROM CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping";
	private static final String _SQL_SELECT_CABDIRECTORY_DLFILEENTRYMAPPING_WHERE =
		"SELECT cabDirectory_DLFileEntryMapping FROM CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping WHERE ";
	private static final String _SQL_COUNT_CABDIRECTORY_DLFILEENTRYMAPPING = "SELECT COUNT(cabDirectory_DLFileEntryMapping) FROM CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping";
	private static final String _SQL_COUNT_CABDIRECTORY_DLFILEENTRYMAPPING_WHERE =
		"SELECT COUNT(cabDirectory_DLFileEntryMapping) FROM CABDirectory_DLFileEntryMapping cabDirectory_DLFileEntryMapping WHERE ";
	private static final String _FINDER_COLUMN_DLFILEENTRYID_DLFILEENTRYID_2 = "cabDirectory_DLFileEntryMapping.dlFileEntryId = ?";
	private static final String _ORDER_BY_ENTITY_ALIAS = "cabDirectory_DLFileEntryMapping.";
	private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No CABDirectory_DLFileEntryMapping exists with the primary key ";
	private static final String _NO_SUCH_ENTITY_WITH_KEY = "No CABDirectory_DLFileEntryMapping exists with the key {";
	private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
				PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
	private static Log _log = LogFactoryUtil.getLog(CABDirectory_DLFileEntryMappingPersistenceImpl.class);
	private static CABDirectory_DLFileEntryMapping _nullCABDirectory_DLFileEntryMapping =
		new CABDirectory_DLFileEntryMappingImpl() {
			@Override
			public Object clone() {
				return this;
			}

			@Override
			public CacheModel<CABDirectory_DLFileEntryMapping> toCacheModel() {
				return _nullCABDirectory_DLFileEntryMappingCacheModel;
			}
		};

	private static CacheModel<CABDirectory_DLFileEntryMapping> _nullCABDirectory_DLFileEntryMappingCacheModel =
		new CacheModel<CABDirectory_DLFileEntryMapping>() {
			public CABDirectory_DLFileEntryMapping toEntityModel() {
				return _nullCABDirectory_DLFileEntryMapping;
			}
		};
}